// 各个的域名
const httpObj = {
    'gitee':'https://gitee.com',
    'github':'https://api.github.com',
}
// 对应的名字
const userObj = {
    'gitee':"chenyongjie123",
    'github':'td-cli'
};
// 模版填写的配置文件
const configFile = {
    'gitee':"",
    'github':'ask.js'
}
/**
 * 每个请求的接口配置文件
 */
class ApiConfig{
    static  type = "github"
    static clone = false
    /**
     * 获取用户下的公开仓库
     * @returns 
     */
    static getListUrl = () => {
        let url = "";
        switch(this.type){
            case 'gitee':
                url = httpObj.gitee + `/api/v5/users/${userObj.gitee}/repos`
                break;
            case 'github':
            default:
                url = httpObj.github + `/orgs/${userObj.github}/repos`
                break;
        }
        return url;
    }
    /**
     * 获取仓库下的tags列表url
     * @param {选择的仓库名字} repo 
     * @returns 
     */
    static getTagsUrl = (repo)=>{
        let url = "";
        switch(this.type){
            case 'gitee':
                url = httpObj.gitee + `/api/v5/repos/${userObj.gitee}/${repo}/tags`
                break;
            case 'github':
            default:
                url = httpObj.github + `/repos/${userObj.github}/${repo}/tags`
                break;
        }
        return url;
    }
    /**
     * 返回下载地址
     * @param {仓库名} repo 
     * @param {tag名} tag 
     * @returns 
     */
    static getDownUrl = (repo,tag)=>{
        let url = "";
        switch(this.type){
            case 'gitee':
                this.clone = true;
                url = `gitee:${httpObj.gitee}/${userObj.gitee}/${repo}${tag?'#'+tag:''}`
                break;
            case 'github':
            default:
                this.clone = false;
                url = `${userObj.github}/${repo}${tag?'#'+tag:''}`
                break;
        }
        return url;
    }
    /**
     * 返回模版填写配置路径
     * @returns 
     */
    static getConfigFile = ()=>{
        return configFile[this.type];
    }
}
module.exports = ApiConfig